package stream;

import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * 四大函数式接口
 *
 * @author
 */
public class Test1 {
    public static void main(String[] args) {

        // 一.核心方法
        // 没有参数

        // 有入参,有出参
        // T -> R
        Function<Integer, String> function = a -> String.valueOf(a + 10);
        System.out.println(function.apply(3));

        // 有入参,无出参
        // T -> void
        Consumer<Integer> consumer = a -> System.out.println(a + 10);
        consumer.accept(4);

        // 无入参,有出参
        // () -> R
        Supplier<Integer> supplier = () -> 5;
        System.out.println(supplier.get());

        // 有入参,有出参
        // T -> Boolean
        Predicate<Integer> predicate = a -> a == 0;
        System.out.println(predicate.test(5));


        // 二.其他方法

        // BiFunction同Function,区别两个入参
        // T K -> R
        BiFunction<Integer, Integer, String> biFunction = (a, b) -> String.valueOf(a + b + 10);
        System.out.println(biFunction.apply(3, 4));

        // BiConsumer同Consumer,区别两个入参
        // T K -> void
        BiConsumer<Integer, Integer> biConsumer = (a, b) -> System.out.println(a + b + 10);
        biConsumer.accept(4, 5);
    }

    public static Function<Integer, String> function(){
        return a -> String.valueOf(a + 10);
    }

}
